import 'package:flutter/material.dart';

enum DialogType {
  INFO,
  WARN,
  ERROR,
  CHECK
}

void showMessage(BuildContext context, String text, [DialogType type,
  VoidCallback onPress]) {
  showDialog(
      context: context,
      builder: (ctx) =>
      new SimpleDialog(
          children: <Widget>[
            new LaksaDialog(
                icon: getIconData(type),
                color: getColor(type),
                text: text,
                onPressed: onPress
            )
          ]
      )
  );
}

IconData getIconData(DialogType type) {
  IconData icon = null;
  switch (type) {
    case DialogType.INFO:
      icon = Icons.info_outline;
      break;
    case DialogType.WARN:
      icon = Icons.warning;
      break;
    case DialogType.ERROR:
      icon = Icons.highlight_off;
      break;
    case DialogType.CHECK:
      icon = Icons.check_circle_outline;
      break;
    default:
      icon = Icons.info_outline;
      break;
  }
  return icon;
}

Color getColor(DialogType type) {
  Color color = null;
  switch (type) {
    case DialogType.INFO:
      color = Colors.yellow[500];
      break;
    case DialogType.WARN:
      color = Colors.blue[500];
      break;
    case DialogType.ERROR:
      color = Colors.red[500];
      break;
    case DialogType.CHECK:
      color = Colors.green[500];
      break;
    default:
      color = Colors.yellow[500];
      break;
  }
  return color;
}

class LaksaDialog extends StatefulWidget {

  final IconData icon;
  final Color color;
  final String text;
  final VoidCallback onPressed;

  const LaksaDialog(
      { Key key, this.icon, this.color, this.text, this.onPressed })
      : super(key: key);

  @override
  _LaksaDialogState createState() => new _LaksaDialogState();

}

class _LaksaDialogState extends State<LaksaDialog> {
  build(BuildContext context) =>
      new SimpleDialogOption(
        onPressed: widget.onPressed,
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            new Icon(widget.icon, size: 36.0, color: widget.color),
            new Padding(
              padding: const EdgeInsets.only(left: 0.0),
              child: new Text(widget.text),
            ),
          ],
        ),
      );
}